package btree;

public class Main {
    public static void main(String[] args) {
        BTree t1 = new BTree(1);
        BTree t2 = new BTree(2);
        BTree t3 = new BTree(3);
        BTree t4 = new BTree(4);
        BTree t5 = new BTree(5);
        BTree t6 = new BTree(6);
        BTree t7 = new BTree(7);

        t1.setLeftChild(t2);
        t1.setRightChild(t3);
        t2.setRightChild(t4);
        t3.setLeftChild(t5);
        t4.setLeftChild(t6);
        t4.setRightChild(t7);

        //定义一个遍历器，这里仅简单输出结点上的数据，也就是它的编号
        Visitor visitor = new Visitor() {
            @Override
            public void visit(BTree node) {
                System.out.print(node.getData() + " ");
            }
        };
        BTreeUtils.preorderTraverse(t1, visitor);
        System.out.println();

        BTreeUtils.preorderTraverseByStack(t1, visitor);
        System.out.println();

        BTreeUtils.inorderTraverse(t1, visitor);
        System.out.println();

        BTreeUtils.inorderTraverseByStack(t1, visitor);
        System.out.println();


        BTreeUtils.postorderTraverseByStack(t1, visitor);
        System.out.println();

        BTreeUtils.postorderTraverse(t1, visitor);
        System.out.println();

    }
}
